/**
 * LangChain AI Writer - IntelliMark版主入口文件
 * 从ai-writer-lite项目迁移并适配
 */

// 导出所有类型、工具和实现
export * from './types';
export * from './utils/langChainConfig';
export * from './utils/promptTemplates';
export * from './utils/aiProviderAdapter';

// 主要导出
import { initializeLangChain, getLangChainManager } from './utils/langChainConfig';
import { WritingAgent, WritingAgentConfig } from './agents/writingAgent';
import { createAgentExecutor } from './agents/agentExecutor';

/**
 * 初始化LangChain AI Writer for IntelliMark
 */
export const initializeAIWriter = async (config?: any) => {
  await initializeLangChain();
  console.log('🎉 LangChain AI Writer for IntelliMark initialized successfully!');
};

/**
 * 创建写作Agent
 */
export const createWritingAgent = (config?: Partial<WritingAgentConfig>): WritingAgent => {
  const defaultConfig: WritingAgentConfig = {
    specialties: ['generate', 'polish', 'expand', 'continue', 'summarize'],
    defaultStyle: 'creative',
    autoContext: true,
    learningEnabled: true,
    collaborationMode: false,
    memoryEnabled: true,
    ...config,
  };

  return new WritingAgent(defaultConfig);
};

/**
 * 快速文本生成
 */
export const generateText = async (
  prompt: string,
  options?: {
    style?: string;
    tone?: string;
    length?: string;
    provider?: string;
  }
) => {
  const { TextGenerationTool } = await import('./tools/textGeneration/textGenerationTool');
  const tool = new TextGenerationTool();

  const result = await tool.execute({
    operation: 'generate',
    prompt,
    style: options?.style || 'neutral',
    tone: options?.tone || 'neutral',
    length: options?.length || 'medium',
  });

  return result;
};

/**
 * 快速文本分析
 */
export const analyzeText = async (
  text: string,
  analysisType: string = 'style'
) => {
  const { TextAnalysisTool } = await import('./tools/textAnalysis/textAnalysisTool');
  const tool = new TextAnalysisTool();

  const result = await tool.execute({
    text,
    analysisType: analysisType as any,
  });

  return result;
};

/**
 * 获取版本信息
 */
export const getVersion = () => {
  return {
    version: '1.0.0',
    name: 'LangChain AI Writer for IntelliMark',
    description: '基于LangChain的IntelliMark智能写作助手',
    langchain: require('langchain/package.json').version,
  };
};

// 默认导出
export default {
  initializeAIWriter,
  createWritingAgent,
  generateText,
  analyzeText,
  getVersion,
  getLangChainManager,
};